home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / freetype.zip / ttcalc32.inc < prev    next >
Text File  |  1996-09-07  |  5KB  |  242 lines

  1. {**********************************************************}
  2. {*                                                        *}
  3. {* The following routines are inline assembly, they are   *}
  4. {* thus processor and bitness specific. Replace them      *}
  5. {* with your own if you want to port the TrueType Engine  *}
  6. {* To different platforms                                 *}
  7. {*                                                        *}
  8. {* There are C equivalents in comments                    *}
  9.  
  10. {**********************************************************}
  11. {* Four operations to convert from Motorola to Intel      *}
  12. {*                                                        *}
  13. {* Make these void macros if you don't need them..        *}
  14.  
  15. (*
  16.    void Do16( unsigned short* S )
  17.    {
  18.      *S = ( *S >> 8 ) | ( *S << 8 );
  19.    }
  20. *)
  21.  
  22. procedure Do16( var S ); assembler;
  23. asm
  24.   push ecx
  25.   mov ecx,[S].dword
  26.   mov ax,[ecx]
  27.   xchg al,ah
  28.   mov [ecx],ax
  29.   pop ecx
  30. end;
  31.  
  32. (*
  33.    void Do16s( unsigned short* S, int Cnt )
  34.    {
  35.      while ( Cnt > 0 )
  36.      {
  37.        *S = ( *S >> 8 ) | ( *S << 8 );
  38.        S++;
  39.        Cnt--;
  40.      }
  41.    }
  42. *)
  43.  
  44. procedure Do16s( var S; Cnt : Int ); assembler; {&USES ebx, ecx }
  45. asm
  46.   mov ebx,[S].dword
  47.   mov ecx,[Cnt]
  48.  @1:
  49.   mov ax,[ebx]
  50.   xchg al,ah
  51.   mov [ebx],ax
  52.   add ebx,2
  53.   dec cx
  54.   jnz @1
  55. end;
  56.  
  57. (*
  58.   void Do32( unsigned long* L )
  59.   {
  60.     *L = ( *L << 24 ) | ( ( *L  << 8 ) & 0x0F00 ) |
  61.          ( ( *L >> 8 ) & 0x00F0 ) | ( *L >> 24 );
  62.   }
  63. *)
  64.  
  65. procedure Do32( var L ); assembler; {&USES ebx}
  66. asm
  67.   mov ebx,[L]
  68.   mov dx,[ebx].word
  69.   mov ax,[ebx+2].word
  70.   xchg al,ah
  71.   xchg dl,dh
  72.   mov [ebx+2].word,dx
  73.   mov [ebx].word,ax
  74. end;
  75.  
  76. (*
  77.   void Do32s( unsigned long* L, int Cnt )
  78.   {
  79.     while ( Cnt > 0 )
  80.     {
  81.       *L = ( *L << 24 ) | ( ( *L  << 8 ) & 0x0F00 ) |
  82.            ( ( *L >> 8 ) & 0x00F0 ) | ( *L >> 24 );
  83.       L++;
  84.       Cnt--;
  85.     }
  86.   }
  87. *)
  88.  
  89. procedure Do32s( var L; Cnt : int ); assembler; {&USES ebx, ecx}
  90. asm
  91.   mov ebx,[L].dword
  92.   mov ecx,[Cnt]
  93.  @1:
  94.   mov dx,[ebx].word
  95.   mov ax,[ebx+2].word
  96.   xchg al,ah
  97.   xchg dl,dh
  98.   mov [ebx+2].word,dx
  99.   mov [ebx].word,ax
  100.   add ebx,4
  101.   dec cx
  102.   jnz @1
  103. end;
  104.  
  105.  
  106.  
  107. {**********************************************************}
  108. {* Calc A*B/C with Intermediate 64 bit precision          *}
  109.  
  110. (*
  111.   long MulDiv( long A, B, C )
  112.   {
  113.     return ((A*B)/C);  // And a good optimising compiler
  114.   }
  115. *)
  116.  
  117. function MulDiv( A, B, C : Int32 ): Int32; assembler; {&USES ebx, ecx}
  118. asm
  119.   mov eax,[A]
  120.   mov ecx,[B]
  121.   mov ebx,[C]
  122.   imul ecx
  123.   idiv ebx
  124. end;
  125.  
  126.  
  127.  
  128. {**********************************************************}
  129. {* 64 Bit Addition                                        *}
  130.  
  131. procedure Add64( var X, Y, Z : Int64 ); assembler; {&USES ebx, edx}
  132. asm
  133.   mov ebx,[X].dword
  134.   mov eax,[ebx]
  135.   mov edx,[ebx+4]
  136.  
  137.   mov ebx,[Y].dword
  138.   add eax,[ebx]
  139.   adc edx,[ebx+4]
  140.  
  141.   mov ebx,[Z].dword
  142.   mov [ebx],eax
  143.   mov [ebx+4],edx
  144. end;
  145.  
  146.  
  147. {**********************************************************}
  148. {* 64 Bit Substraction                                    *}
  149.  
  150. procedure Sub64( var X, Y, Z : Int64 ); assembler; {&USES ebx, edx}
  151. asm
  152.   mov ebx,[X].dword
  153.   mov eax,[ebx]
  154.   mov edx,[ebx+4]
  155.  
  156.   mov ebx,[Y].dword
  157.   sub eax,[ebx]
  158.   sbb edx,[ebx+4]
  159.  
  160.   mov ebx,[Z].dword
  161.   mov [ebx],eax
  162.   mov [ebx+4],edx
  163. end;
  164.  
  165.  
  166. {**********************************************************}
  167. {* Multiply two Int32 to an Int64                         *}
  168.  
  169. procedure MulTo64( X, Y : Int32; var Z : Int64 ); assembler; {&USES ebx, edx }
  170. asm
  171.   mov ebx,[Z].dword
  172.   mov eax,[X]
  173.   imul [Y]
  174.   mov [ebx],eax
  175.   mov [ebx+4],edx
  176. end;
  177.  
  178.  
  179. {**********************************************************}
  180. {* Divide an Int64 by an Int32                            *}
  181.  
  182. function Div64by32( var X : Int64; Y : Int32 ) : Int32; assembler;
  183.          {&USES ebx, edx}
  184. asm
  185.   mov ebx,[X].dword
  186.   mov eax,[ebx]
  187.   mov edx,[ebx+4]
  188.   idiv [Y]
  189. end;
  190.  
  191.  
  192. {**********************************************************}
  193. {* MSB index ( return -1 for 0 )                          *}
  194.  
  195. function Order64( var Z : Int64 ) : int; assembler; {&USES ebx, ecx, edx}
  196. asm
  197.   mov ebx,[Z].dword
  198.   mov eax,[ebx  ]
  199.   mov edx,[ebx+4]
  200.   mov ebx,63
  201.   mov ecx,$80000000
  202.  
  203.  @1:
  204.   test edx,ecx
  205.   jnz @3
  206.   dec ebx
  207.   ror ecx,1
  208.   jns @1
  209.  
  210.  @2:
  211.   test eax,ecx
  212.   jnz @2
  213.   dec ebx
  214.   ror ecx,1
  215.   jns @2
  216.  
  217.  @3:
  218.   mov eax,ebx
  219. end;
  220.  
  221.  
  222. {**********************************************************}
  223. {* MSB index ( return -1 for 0 )                          *}
  224.  
  225. function Order32( Z : Int32 ) : int; assembler; {&USES ebx, ecx, edx}
  226. asm
  227.   mov eax,[Z]
  228.   mov ebx,31
  229.   mov ecx,$80000000
  230.  
  231.  @1:
  232.   test edx,ecx
  233.   jnz @2
  234.   dec ebx
  235.   ror ecx,1
  236.   jns @1
  237.  
  238.  @2:
  239.   mov eax,ebx
  240. end;
  241.  
  242.